#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author:余振新
@file: 登录页.py
@time: 2023/03/31
"""
from common.base_action import BaseAction
from common.base_driver import BaseDriver
from common.gol import get_value
from page.首页 import 登录页, 聚合页
from common.read_yaml import read_yaml

data = read_yaml()["login_唐鹏玥"]
data_username = data["username"]
data_pwd = data["pwd"]
data_expect = data["expect"]

data = read_yaml()["login_yg0144"]
yg0144_username = data[0]["username"]
yg0144_pwd = data[0]["pwd"]
yg0144_expect = data[0]["expect"]


class Login(BaseAction):
    def __init__(self, _driver):
        # 调用父类的 __init__ 方法来初始化实例变量
        super().__init__(_driver)

    def login(self, username, pwd, expect):
        self.send_keys(登录页.用户名输入框, username)
        self.send_keys(登录页.密码输入框, pwd)
        self.click(登录页.登录按钮)
        result = self.is_text_in_element(聚合页.登录人姓名, expect)
        return result

    # 调试过程中且不使用缓存情况下可以使用该管理员账号进行登录
    def login_唐鹏玥(self):
        self.send_keys(登录页.用户名输入框, data_username)
        self.send_keys(登录页.密码输入框, data_pwd)
        self.click(登录页.登录按钮)
        result = self.is_text_in_element(聚合页.登录人姓名, data_expect)
        return result

    def login_邹纲(self):
        self.send_keys(登录页.用户名输入框, yg0144_username)
        self.send_keys(登录页.密码输入框, yg0144_pwd)
        self.click(登录页.登录按钮)
        result = self.is_text_in_element(聚合页.登录人姓名, yg0144_expect)
        return result


if __name__ == "__main__":
    BaseDriver().get_driver()
    driver = get_value("driver")
    login = Login(driver)
    login.login("19999999999", "a123456", "123")
